package sundun.sharding.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import sundun.sharding.constant.ShardingConstant;
import sundun.sharding.properties.ShardingJdbcProperties;
import sundun.sharding.utils.ShardingAlgorithmUtil;

/**
 * ShardingTablesLoadRunner
 * 项目启动后，
 *
 * @author: zxl
 * @date: 2024/07/31 13:02
 */

@Slf4j
@ConditionalOnProperty(name = ShardingConstant.SPRING_SHARDING_SPHERE_ENABLED, havingValue = "true")
public class ShardingTablesLoadRunner implements CommandLineRunner {

    @Override
    public void run(String... args) {
        // 读取已有分表，进行缓存
        ShardingAlgorithmUtil.tableNameCacheReloadAll();
        log.info("ShardingSphere组件初始化成功！");
        log.info("读取已有分表，添加缓存成功！");
    }
}
